package com.example.admin.yuejian21.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.admin.yuejian21.Adapter.NFinOrderAdapter;
import com.example.admin.yuejian21.Bean.UserOrder;
import com.example.admin.yuejian21.Model.UserModel;
import com.example.admin.yuejian21.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class NfinOrderFragment extends Fragment {
    private RecyclerView recyclerView;
    private int user_id;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_nfin_order, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.nfinorder_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        user_id = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("user_id",0);
        showData();
        return view;
    }

    private void showData() {
        UserModel userModel = new UserModel();
        Call<List<UserOrder>> call = userModel.getfinorder(0, user_id);
        call.enqueue(new Callback<List<UserOrder>>() {
            @Override
            public void onResponse(Call<List<UserOrder>> call, Response<List<UserOrder>> response) {
                List<UserOrder> mDataList = response.body();
                recyclerView.setAdapter(new NFinOrderAdapter(getActivity(), mDataList));
            }

            @Override
            public void onFailure(Call<List<UserOrder>> call, Throwable t) {

            }
        });
    }
}
